<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.w3.org/1999/xhtml">
    
    <head>
        <meta charset="UTF-8">
        <title>管理员添加</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
        <link rel="stylesheet" th:href="@{/asserts/css/adminfont.css}">
    	<link rel="stylesheet" th:href="@{/asserts/css/xadmin.css}">
    	<link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css" rel="stylesheet" />
        <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js" charset="UTF-8"></script>
        <script th:src="@{/asserts/lib/layui/layui.js}" charset="UTF-8"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js" charset="UTF-8"></script>
        <script th:src="@{/asserts/js/xadmin.js}"  type="text/javascript"  charset="UTF-8"></script>
        <script th:src="@{/asserts/js/admin/administrator.js}"  type="text/javascript"  charset="UTF-8"></script>
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form" >
                  <div class="layui-form-item">
                      <label for="username" class="layui-form-label">
                          <span class="x-red">*</span>登录名
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="username" name="username"  lay-verify="required" autocomplete="off" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                          <span class="x-red">*</span>将会成为唯一的登入名
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="phone" class="layui-form-label">
                          <span class="x-red">*</span>邮箱
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="email" required="" lay-verify="email" autocomplete="off" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label class="layui-form-label"><span class="x-red">*</span>角色</label>
                      <div class="layui-input-block" id="rolelist">
                        <input type="radio" name="role"  lay-skin="primary" title="高级管理员" value="1" checked="checked" >
                        <input type="radio" name="role" lay-skin="primary" title="审核管理员" value="2">
                        <input type="radio" name="role" lay-skin="primary" title="景点攻略管理员" value="3">
                        
                      </div>
                  </div>
                  
                  <div class="layui-form-item">
                      <label for="L_pass" class="layui-form-label">
                          <span class="x-red">*</span>密码
                      </label>
                      <div class="layui-input-inline">
                          <input type="password" id="L_pass" name="pass" required="" lay-verify="pass"  autocomplete="new-password" class="layui-input">
                      </div>
                      <div class="layui-form-mid layui-word-aux">
                         <span class="x-red">*</span>8到16个字符
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="rpassword" class="layui-form-label">
                          <span class="x-red">*</span>确认密码
                      </label>
                      <div class="layui-input-inline">
                          <input type="password" id="L_repass" name="repass" required="" lay-verify="repass" autocomplete="off" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label">
                      </label>
                      <button  lay-filter="add" class="layui-btn" lay-submit="" >添加</button>
                  </div>
                  </form>
            </div>
        </div>
        <script>
        toastr.options = 
    	{
            positionClass: "toast-top-center",
            closeButton: true,
            timeOut:"1000",
        };
        layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;

                //自定义验证规则
                form.verify({
                    nikename: function(value) {
                        if (value.length < 5) {
                            return '昵称至少得5个字符啊';
                        }
                    },
                    pass: [/(.+){8,12}$/, '密码必须8到12位'],
                    repass: function(value) {
                        if ($('#L_pass').val() != $('#L_repass').val()) {
                            return '两次密码不一致';
                        }
                    }
                });

                //监听提交
                form.on('submit(add)',
                function(data) {
                	var msg='失败';
                    //发异步,提交数据
                    $.ajax({
                    	type:"post",
                    	url:"/admin/aa04/insertAdmin",
                    	data:JSON.stringify({username:$("#username").val(),email:$("#email").val(),
                    		password:$("#L_pass").val(),role:$("input:radio:checked").val()}),
                    	contentType: "application/json",
                    	dataType: "text",
                    	async:false,
                    	success:function(result)
                    	{
                    		msg=result;
                    		if(msg=='插入成功!')
                    		{
                    			layer.alert(msg, {icon: 6},function() {
                                        xadmin.close();
                                        xadmin.father_reload();
                                    }
                                );		
                    		}
                    		else
                    		{
                    			toastr.warning(msg);
                    		}
                    	
                    	},
                    	error:function(e)
                    	{
                    		toastr.error("网络错误");
                    	}
                    });
                    
                    return false;
                });

            });
        </script>
    </body>

</html>
